package aeronef;

import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import aeronef.appStates.GameState;
import aeronef.appStates.MenuState;
import aeronef.loader.XmlLoader;
import com.jme3.system.AppSettings;

public class MainApp extends SimpleApplication {

    MenuState menuState;
    GameState gameState;
    
    public static void main(String[] args) {
        MainApp app = new MainApp();
        app.setShowSettings(false);
        AppSettings settings = new AppSettings(true);
        settings.setResolution(1280, 720);
        settings.setBitsPerPixel(32);
        app.setSettings(settings);
        app.start();
    }

    @Override
    public void simpleInitApp() {
      menuState = new MenuState();
      gameState = new GameState();
      gameState.setResWidth(settings.getWidth());
      gameState.setResHeight(settings.getHeight());
      assetManager.registerLoader(XmlLoader.class, "xml");
      
      goToGame();
    }
    
    @Override
    public void simpleUpdate(float tpf) {
        stateManager.update(tpf);
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }

    public void goToGame() {
        getStateManager().detach(menuState);
        getStateManager().attach(gameState);
    }
    
    public void goToMenu() {
        getStateManager().detach(gameState);
        getStateManager().attach(menuState);
    }
    
    
    public void startMenu() { menuState.goToStartScreen(); }
    public void hostLobby() { menuState.goToHostLobbyScreen(); }
}
